package tt.dz.biz.job;

import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import tt.dz.biz.service.account.AccountingRecordService;
import tt.dz.common.AppContxtUtil;
import tt.dz.common.DateUtil;
import tt.dz.common.DzConstants;
import tt.dz.common.DzConstants.sysJob;
import tt.dz.common.LogUtil;
import tt.dz.vo.TranInfoVO;

public class AccountDividendJob
  extends AbstractJob
{
  protected void executeJob(JobExecutionContext arg0)
    throws JobExecutionException
  {
    try
    {
      AccountingRecordService accountingRecordService = (AccountingRecordService)AppContxtUtil.getBean("accountingRecordService");
      LogUtil.info("记账开始时间：" + DateUtil.getDateTimeFormatter());
      List<TranInfoVO> tranInfoList = accountingRecordService.queryTranWaitingForAccounting();
      if (!CollectionUtils.isEmpty(tranInfoList))
      {
        accountingRecordService.updateTranInfoAccounting(tranInfoList);
        accountingRecordService.saveAccountDevidend(tranInfoList);
      }
      LogUtil.info("记账完成时间:" + DateUtil.getDateTimeFormatter());
    }
    catch (Exception e)
    {
      LogUtil.error("记账 srvice 发生异常", e);
    }
  }
  
  protected String getJobCode()
  {
    return DzConstants.sysJob.RECORD_DIVIDEND_JOB.value();
  }
}
